$(function(){
    var
        oCartListA    = $('.cart-top .cart-list a'),
        oCartListA1  =$ ('.cart-top .cart-list .a1'),
        oCartListA2  =$ ('.cart-top .cart-list .a2'),
        oCartListA3  =$ ('.cart-top .cart-list .a3'),
        oHintP       =$ ('.hint p');
    oCartListA.click(function(){
        var aIndex=$(this).index();
        oCartListA.removeClass('a1').eq(aIndex).addClass('a1');
        oHintP.css({display:'none'}).eq(aIndex).css({display:'block'})
    });

    var
        sGoods = getCookie('goods'),
        aGoods = JSON.parse(sGoods),
        oUl    = $('.list_content'),
        oListTitle = $ ('.list-title'),
        oHint  =  $ ('.hint'),
        sUlHtml = '',
        Sum= 0,
        oGoodPrice = $ ('.good-price a');
    for(var i =0; i < aGoods.length; i++) {
        sUlHtml +='<ul><li class="list_content_left"><p class="good_img"><a href="javascript:;"><img src="'+ aGoods[i].goodsSrc +'"></a></p><p class="good_name"><span>'+ aGoods[i].goodsPinpai +'</span><span class="sp11">'+aGoods[i].goodsType+'</span><span class="sp11">'+'尺寸 ：'+aGoods[i].goodSize+'</span></p></li><li class="danjia">'+'￥'+aGoods[i].goodsPrice+'.00'+'</li><li><div class="number_choose"><span class="number_reduce_none">'+ '-' +'</span><span class="quantity_number">'+aGoods[i].goodsNum+'</span><span class="number_increase">'+ '+'+'</span></div></li><li></li> <li class="xiaoji">'+'¥'+aGoods[i].goodsPrice*aGoods[i].goodsNum+'.00'+'</li><li><img class="list_content_delete" src="'+'../images/icon_delete.png'+'"></li></ul>'

       Sum+=aGoods[i].goodsPrice*aGoods[i].goodsNum
    }
    oUl.prepend(sUlHtml);
    if(!oUl.html()==true){
        oHint.css({display:'block'});
        oListTitle.css({display:'none'});
    }



    oGoodPrice.html('¥'+Sum+'.00');

    var
        oSub = $ ('.list_content .number_reduce_none'),
        oAdd = $ ('.list_content .number_increase'),
        oNum = $ ('.list_content .quantity_number'),
        numBTn = true,
        numBTn1 = true,
        oXiaoji = $('.xiaoji'),
        aNum=oNum.html(),
        oXXImg  =$('.list_content_delete'),
        oDanjia  = $ ('.danjia');

    var
        oNavRight  = $ ('.nav-right .good-number a');
    oNavRight.html(aGoods.length);

    oSub.click(function(){
        var iNumIndex = oSub.index($(this));
        if(numBTn){
            if(aNum<=1){
                numBTn=false;
                numBTn1 = true;
            }else {
                aNum--;
                oNum.eq(iNumIndex).html(aNum);
                oXiaoji.eq(iNumIndex).html('￥'+oDanjia.eq(iNumIndex).html().split('￥')[1]*aNum+'.00')
            }
        }
    });
    oAdd.click(function(){
         var aNumIndex = oAdd.index($(this));
         if(numBTn1) {
            aNum++;
            if (aNum > 4) {
                numBTn1 = false;
                numBTn=true;
            }else{
                oNum.eq(aNumIndex).html(aNum);
                oXiaoji.eq(aNumIndex).html('￥' + oDanjia.eq(aNumIndex).html().split('￥')[1] * aNum+'.00')
            }
        }
    });
    var oCookUl    = $('.list_content ul');

    oXXImg.click(function(){
        var iImgIndex = oXXImg.index($(this));
        oCookUl.eq(iImgIndex).remove();
        aGoods.splice(iImgIndex,1);
        setCookie('goods', JSON.stringify(aGoods), 7, '/');
    });
});


